/**
 * Created by Administrator on 2018/10/8.
 */
+function ($) {
    'use strict';
    var ExtBtnSearch = function (f, e) {
        this.$element =  $(f);
        this.options = $.extend({}, ExtBtnSearch.DEFAULTS, e);
        this.init()
    };
    ExtBtnSearch.DEFAULTS = {
    };
    ExtBtnSearch.prototype.init = function () {
        var $btnSearch = this.$element,$pageBox = this.$element.closest('.page-content'),
            $searchFormContainer = $pageBox.find('.list-filter-form');
        if ($btnSearch.length > 0 && $searchFormContainer.length > 0) {
            var  boltDataGrid =  $pageBox.find("[data-toggle='boltDataGrid']"),space = $searchFormContainer.outerHeight()+10;
            console.log(space)
            $btnSearch.unbind("click").click(function () {
                if ($searchFormContainer.hasClass("hide")) {
                    $searchFormContainer.removeClass("hide");
                    $btnSearch.addClass("active");
                    $btnSearch.html($btnSearch.html().replace("查询", "隐藏"))
                    boltDataGrid.boltDataGrid('resetView',{space:-space})
                } else {
                    $searchFormContainer.addClass("hide");
                    $btnSearch.removeClass("active");
                    $btnSearch.html($btnSearch.html().replace("隐藏", "查询"))
                    boltDataGrid.boltDataGrid('resetView',{space:space})
                }
                return false
            });
            if (!$searchFormContainer.hasClass("hide")) {
                $btnSearch.removeClass("hide");
                $btnSearch.addClass("active");
                $btnSearch.html($btnSearch.html().replace("隐藏", "查询"))
            }
        }
    }
    function Plugin(e) {
        return this.each(function () {
            var h = $(this);
            var g = h.data("extBtnSearch");
            var f = typeof e == "object" && e;
            if (!g) {
                h.data("extBtnSearch", (g = new ExtBtnSearch(this, f)))
            }
            if (typeof e == "string") {
                g[e]()
            }
        })
    }
    $.fn.extBtnSearch = Plugin
    $.fn.extBtnSearch.Constructor = ExtBtnSearch;

    Bolt.addComponent({
        name: "ExtBtnSearch",
        plugin: Plugin,
        runPoint: Bolt.eventType.afterAjaxPageShow,
        expr: "a[data-toggle='extBtnSearch']",
        order: 800
    })
}(jQuery)

